package com.study.zzedu.ui.teacherinfo;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.study.zzedu.R;
import com.study.zzedu.adapter.TeachersCourseAdapter;
import com.study.zzedu.ui.exercise.view.NoScrollGridView;
import com.study.zzedu.utils.AppConstant;
import com.study.zzedu.utils.OkHttpUtils;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by kiros on 2020/9/5.
 * 课程页面
 */

public class TeacherInfoActivity extends Activity {

    RecyclerView rl_list;
    private RecyclerView.LayoutManager layoutManager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_teacher_info);

        findViewById(R.id.rl_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        rl_list = findViewById(R.id.rl_teacher_list);
        getTeacherInfo();
    }


    private void getTeacherInfo() {
        OkHttpUtils.getInstance(TeacherInfoActivity.this).getJsonForString(OkHttpUtils.BASE_URL + "/appCourse/queryCourseTeachers",
                new String[]{"courseCode"}, new String[]{AppConstant.courseCode}, new OkHttpUtils.HttpCallBack() {

                    @Override
                    public void onSuccess(String obj) {
                        try {
                            JSONObject jObject = new JSONObject(obj);
                            if (0 == jObject.getInt("code")) {
                                JSONArray jsonArray = jObject.getJSONArray("data");
                                if (jsonArray.length() > 0) {
                                    TeacherInfoActivity.this.findViewById(R.id.rl_default_teacher_info).setVisibility(View.GONE);

                                    layoutManager = new LinearLayoutManager(TeacherInfoActivity.this, LinearLayoutManager.VERTICAL, false);
                                    TeachersCourseAdapter adapter = new TeachersCourseAdapter(TeacherInfoActivity.this, jsonArray);
                                    rl_list.setLayoutManager(layoutManager);
                                    rl_list.setAdapter(adapter);
                                }
                            } else {
                            }
                        } catch (Exception e) {
                            e.toString();
                        }
                    }

                    @Override
                    public void onSuccess(JSONObject obj) {
                    }

                    @Override
                    public void onError(String msg) {
                    }
                });
    }
}
